﻿@page "/converter"
@using System.Text.Json
@using Tool.Services
@inject PythonService _pythonService
@inject IJSRuntime jSRuntime
@inject ISnackbar snackbar;

<PageTitle>Coder</PageTitle>
<MudText Typo="Typo.h3" GutterBottom="true">彼岸</MudText>
<MudGrid>
    <MudItem xs="6">
        <MudTextField @bind-Value="_db" Label="数据库名称" Variant="Variant.Text" Adornment="Adornment.Start"
                      AdornmentIcon="@Icons.Material.Filled.LockPerson" Clearable="true" />
    </MudItem>
    <MudItem xs="6">
        <MudButton Class="align-self-center" FullWidth="true" Disabled="@_processing" OnClick="GetVowelsCount" Variant="Variant.Filled" Color="Color.Primary">
            @if (_processing)
            {
                <MudProgressCircular Class="ms-n1" Indeterminate="true" />
                <MudText Class="ms-2">Processing</MudText>
            }
            else
            {
                <MudText>mysql to dm</MudText>
            }
        </MudButton>
    </MudItem>
</MudGrid>
<MudSpacer/>
<MudText Typo="Typo.body2" id="sqlResult"></MudText>
@code {
    private string _result = string.Empty;
    private string _db = string.Empty;
    private bool _processing = false;
    private async Task GetVowelsCount()
    {
        try
        {
            _processing = true;
            // 读取 Python 脚本
            // await _pythonService.ImportLib("mysql_to_dm.py");

            await jSRuntime.InvokeVoidAsync("MyLib.convertToDm", _db);

        }
        catch (Exception ex)
        {
            snackbar.Add(ex.Message, Severity.Error);
        }
        finally
        {
            _processing = false;
        }

    }
}
